// ===============================================
// dic_entity
//
// Create by Will on 9/3/2024 12:44
// Copyright @polynesia.All rights reserved.
// ===============================================

import 'dart:convert';

import 'package:json_annotation/json_annotation.dart';

/// This allows the `DicEntity` class to access private members in
/// the generated file. The value for this is *.g.dart, where
/// the star denotes the source file name.
part 'dic_entity.g.dart';

/// An annotation for the code generator to know that this class needs the
/// JSON serialization logic to be generated.
@JsonSerializable(genericArgumentFactories: true)
class DicEntity {
  const DicEntity({
    this.id,
    this.name,
    this.title,
    this.thumb,
    this.contentCount,
  });

  /// A necessary factory constructor for creating a new DicEntity instance
  /// from a map. Pass the map to the generated `_$DicEntityFromJson()` constructor.
  /// The constructor is named after the source class, in this case, DicEntity.
  factory DicEntity.fromJson(Map<String, dynamic> json) =>
      _$DicEntityFromJson(json);

  final int? id;
  final String? name;
  final String? title;
  final String? thumb;
  @JsonKey(name: 'content_count')
  final int? contentCount;

  /// `toJson` is the convention for a class to declare support for serialization
  /// to JSON. The implementation simply calls the private, generated
  /// helper method `_$DicEntityToJson`.
  Map<String, dynamic> toJson() => _$DicEntityToJson(this);

  bool isEmpty() {
    const DicEntity entity = DicEntity();
    // if (entity.toString() == toString()) {
    //   return true;
    // }
    return jsonEncode(entity) == jsonEncode(this);
  }
}
